package com.seveneight.baijiesteward.ui.user.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.base.BaseFragmentBack;
import com.seveneight.baijiesteward.base.Message;
import com.seveneight.baijiesteward.base.MessageEvent;
import com.seveneight.baijiesteward.utils.MDialog;
import com.seveneight.baijiesteward.utils.PreferencesUtil;
import com.seveneight.baijiesteward.utils.SPUtils;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by user1 on 2018/2/11.
 */

public class SettingFragment extends BaseFragmentBack implements View.OnClickListener {

    private ImageView iv_back;
    private TextView tv_title;
    private RelativeLayout layout_exit;
    private MDialog dialog;

    @Override
    protected int getContentView() {
        return R.layout.fragment_setting;
    }

    public static SettingFragment newInstance() {
        Bundle args = new Bundle();
        SettingFragment fragment = new SettingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initView() {
        iv_back = findView(R.id.iv_back);
        tv_title = findView(R.id.tv_title);
        tv_title.setText("设置");
        layout_exit = findView(R.id.layout_exit);
        dialog = new MDialog(mContext, "正在退出...");
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {
        iv_back.setOnClickListener(this);
        layout_exit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                _mActivity.onBackPressed();
                break;
            case R.id.layout_exit:
                dialog.showLoadingDialog();
                checkOut();
                break;
        }
    }

    private void checkOut() {
        setting.setIsLogin(false);
        PreferencesUtil.put(getContext(),PreferencesUtil.userId, "");
        EventBus.getDefault().post(new MessageEvent(Message.CHECK_OUT));
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dialog.hideDialog();
                _mActivity.onBackPressed();
            }
        }, 2000);
    }
}
